package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.redisdemo.RdsServiceTest;

//@EnableScheduling
@EnableAutoConfiguration(exclude = { DataSourceTransactionManagerAutoConfiguration.class,
        DataSourceAutoConfiguration.class})
@SpringBootApplication
@RestController
@EnableCaching
public class DockertestApplication {

	
	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext run = SpringApplication.run(DockertestApplication.class, args);
		try {
			RdsServiceTest bean = run.getBean(RdsServiceTest.class);
			bean.ListOperations();
			
			System.out.println("start success=========");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			run.close();
		}
	}
	
//	@Scheduled(cron = "0/2 * * * * * ")
//	public void testQuartz() {
//		System.out.print(Thread.currentThread().getName());
//		System.out.println("test quartz=====a=a=a=");
//	}
	
	@RequestMapping("/test")
	public String test() {
		return "this is test";
	}

	@ControllerAdvice
	public class MyExceptionHandler {

	    @ExceptionHandler(value =Exception.class)
		public String exceptionHandler(Exception e){
			System.out.println("未知异常！原因是:"+e);
	       	return e.getMessage();
	    }
	}
}
